﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Services.Contracts.DTO.Infos;
using Demo.Services.Services.Impl.DomainObjects;
using Demo.CommonBase.Logging;
using Demo.CommonBase.Exceptions;
using System.Reflection;
using Demo.CommonBase.DTO.Infos;
using Demo.CommonBase.DTO.Filters;
using Demo.Services.Contracts.DTO.Filters;

namespace Demo.Services.Services.Impl.Managers
{
    public class ResourceManager
    {
        public ResourceResultInfo GetResources(PaginationInfo pagin, ResourceFilter filters)
        {
            ResourceResultInfo result = null;
            ResourceDomainObject resourcedo;
            try
            {
                //Logger.Info();
                resourcedo = new ResourceDomainObject();
                result = resourcedo.GetResources(pagin, filters);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public ResourceInfo GetResourceById(int id)
        {
            ResourceInfo result = null;
            ResourceDomainObject resourcedo;
            try
            {
                //Logger.Info();
                resourcedo = new ResourceDomainObject();
                result = resourcedo.GetResourceById(id);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public void DeleteResource(int id)
        {            
            ResourceDomainObject resourcedo;
            try
            {
                //Logger.Info();
                resourcedo = new ResourceDomainObject();
                resourcedo.DeleteResource(id);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }            
        }

        public void SaveResource(ResourceInfo resource)
        {           
            ResourceDomainObject resourcedo;
            try
            {
                //Logger.Info();
                resourcedo = new ResourceDomainObject();
                resourcedo.SaveResource(resource);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }            
        }     

        public CommonComboBoxPagingInfo GetResourceByName(ComboBoxFilter filter)
        {
            CommonComboBoxPagingInfo result = null;
            ResourceDomainObject resourcedo;
            try
            {
                Logger.Info();
                resourcedo = new ResourceDomainObject();
                result = resourcedo.GetResourceByName(filter);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public List<TecnologyInfo> getAssignedTecnologies(int resourceId)
        {
            List<TecnologyInfo> result = null;
            ResourceDomainObject resourcedo;
            try
            {
                //Logger.Info();
                resourcedo = new ResourceDomainObject();
                result = resourcedo.getAssignedTecnologies(resourceId);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public List<TecnologyInfo> getUnAssignedTecnologies(int resourceId)
        {
            List<TecnologyInfo> result = null;
            ResourceDomainObject resourcedo;
            try
            {
                //Logger.Info();
                resourcedo = new ResourceDomainObject();
                result = resourcedo.getUnAssignedTecnologies(resourceId);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public IList<ProjectReportInfo> GetResourceAssignment()
        {
            ResourceDomainObject resourceDO;
            IList<ProjectReportInfo> result;
            try
            {
                //Logger.Info();
                resourceDO = new ResourceDomainObject();
                result = resourceDO.GetResourceAssignment();
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public bool ValidationResource(ResourceFilter filter)
        {
            bool result = false;
            ResourceDomainObject resourceDO;
            try
            {
                Logger.Info();
                resourceDO = new ResourceDomainObject();
                result = resourceDO.ValidationResource(filter);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

    }
}
